package com.csglxt.view.action;

import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.ServletActionContext;

import com.csglxt.utils.HttpClient;
import com.opensymphony.xwork2.ActionSupport;

/**
 * 
 * @ClassName: WeatherAction
 * @Description: 天气预报控制器
 * @author Delver_Si
 * @date 2015-5-29 上午12:00:25
 * 
 */
@SuppressWarnings("serial")
public class WeatherAction extends ActionSupport {

    /**
     * 
     * @Title: info
     * @Description: 获取天气预报信息
     * @param
     * @return
     * @throws
     */
    public void info() throws Exception {

        String ip = ServletActionContext.getRequest().getRemoteAddr();
        System.out.println(ip);
        String weatherInfo = null;
        try {
            weatherInfo = HttpClient.getWeatherJson(ip);
        } catch (Exception e) {
            weatherInfo = HttpClient.getWeatherJson("221.234.230.1");
        }
        System.out.println(weatherInfo);
        HttpServletResponse response = ServletActionContext.getResponse();
        response.setContentType("text/html");
        response.setCharacterEncoding("utf-8");
        response.getWriter().print(weatherInfo);
    }

}
